﻿#region

using System;

#endregion

namespace TSharp.Core.Message
{
    /// <summary>
    ///     消息处理机制情景上下文
    ///     <para>by tangjingbo at 2009/11/20 23:28</para>
    /// </summary>
    public interface ISituation
    {
        /// <summary>
        ///     向所有监听者广播消息，消息处理完成之后才返回。
        /// </summary>
        /// <typeparam name="TMessage">The type of the message.</typeparam>
        /// <param name="message">消息对象.</param>
        /// <returns>返回消息处理过程中的一些信息</returns>
        IMessageResult<TMessage> Broadcast<TMessage>(TMessage message);

        /// <summary>
        ///     向所有监听者广播消息，消息处理完成之后才返回。
        /// </summary>
        /// <typeparam name="TMessage">The type of the message.</typeparam>
        /// <param name="message">消息对象.</param>
        /// <param name="maxDistance">最大广播深度.</param>
        /// <returns>返回消息处理过程中的一些信息</returns>
        IMessageResult<TMessage> Broadcast<TMessage>(
            TMessage message, int maxDistance);


        /// <summary>
        ///     声明监听某消息
        ///     <para>监听器格式</para>
        ///     <para>(sender, message, transmitter) =>{}</para>
        /// </summary>
        /// <typeparam name="TMessage">消息类型</typeparam>
        /// <param name="listener">
        ///     监听器委托.
        ///     <para>监听器格式</para>
        ///     <para>(sender, message, transmitter) =>{}</para>
        /// </param>
        /// <returns></returns>
        IRegisterHandle<TMessage> Register<TMessage>(IHandle<TMessage> listener);

        /// <summary>
        ///     声明监听某消息
        /// </summary>
        /// <param name="listener">The listener.</param>
        /// <returns>IRegisterHandle[][].</returns>
        IRegisterHandle[] Register(IHandle listener);

        /// <summary>
        ///     反注册消息
        /// </summary>
        /// <param name="listener">The listener.</param>
        /// <returns>IRegisterHandle[][].</returns>
        void UnRegister(IHandle listener);

        /// <summary>
        ///     声明监听某消息
        ///     <para>by tangjingbo at 2009/12/14 22:00</para>
        /// </summary>
        /// <typeparam name="TMessage">The type of the message.</typeparam>
        /// <param name="listener">
        ///     监听器委托.
        ///     <para>监听器格式</para>
        ///     <para>(sender, message, transmitter) =>{}</para>
        /// </param>
        /// <param name="order">消息执行优先级</param>
        /// <returns></returns>
        IRegisterHandle<TMessage> Register<TMessage>(IHandle<TMessage> listener, int order);
    }
}